package xyz.lwm.lazycat.aop.matcher;

import xyz.lwm.lazycat.utility.CollectionUtil;
import xyz.lwm.lazycat.utility.matcher.Matcher;

class ArrayMatcher<T> implements Matcher<T[]> {

    private final Matcher<T> matcher;

    public ArrayMatcher(Matcher<T> matcher) {
        this.matcher = matcher;
    }

    @Override
    public boolean matches(T[] target) {
        if (CollectionUtil.isNotEmpty(target)) {
            for (T t : target) {
                if (matcher.matches(t)) {
                    return true;
                }
            }
        }
        return false;
    }

}
